package com.gitlab.bootren.data.core.jpa;

import com.gitlab.bootren.data.core.query.ICondition;
import com.gitlab.bootren.data.core.jpa.cmd.Command;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Created by serv on 14-5-29.
 */
@NoRepositoryBean
public interface PlatformJpaRepository<T,ID extends Serializable> extends JpaRepository<T,ID> {

    /**
     * Returns a single entity matching the given condition.
     *
     * @param condition
     * @return
     */
    T findOne(String condition, Object... objects);


    /**
     * Returns all entities matching the given condition.
     *
     * @param condition
     * @return
     */
    List<T> findAll(String condition, Object... objects);


   

    /**
     * Returns all entities matching the given condition applying the given {@link org.springframework.data.domain.Sort}s.
     *
     * @param condition
     * @param sort
     * @return
     */
    List<T> findAll(String condition, Sort sort, Object... objects);

    /**
     * Returns a {@link org.springframework.data.domain.Page} of entities matching the given condition.
     *
     * @param condition
     * @param pageable
     * @return
     */
    Page<T> findAll(String condition, Pageable pageable, Object... objects);

    /**
     * Returns the number of instances that the given condition will return.
     *
     *
     * @param condition the condition to count instances for
     * @return the number of instances
     */
    long count(String condition, Object... objects);


    /**
     * 通过ID的集合删除条目
     * @param ids
     */
    void deleteByIds(Iterable<ID> ids);

    /**
     * 获取当前DAO对应的实体模型
     * @return
     */
    Class<T> getEntityClass();

    /**
     * 执行自定义命令
     * @param command
     * @return
     */
    @Deprecated
    <S> S executeCommand(Command command);

    /**
     * 通过一个sql 获取 一个list<map> 结果集
     * @param sql
     * @return
     */
    List<Map<String,Object>> nativeQuery4Map(String sql);

    /**
     * 通过一个sql 获取 一个list<map> 结果集
     * @param sql sql 语句
     * @param pageable 分页对象
     * @return
     */
    public Page<Map> nativeQuery4Map(String sql, Pageable pageable);

    /**
     * 通过一个sql 查询一个值  比如: max count min等
     * @param sql
     * @return
     */
    public Object nativeQuery4Object(String sql);
    
    
    public Page<T> findAll(ICondition condition, Pageable pageable);
    
    
    public List<T> findAll(ICondition condition, Sort sort);
    
    
 
    public List<T> findAll(ICondition condition);
    
    
    public T findOne(ICondition condition);
 
    public long count(ICondition condition) ;
    
    

}
